package cn.francis.chatplatform.modules.session.service.impl;

import cn.francis.chatplatform.modules.session.bo.CreateSessionBO;
import cn.francis.chatplatform.modules.session.vo.TestVO;
import cn.francis.chatplatform.modules.session.vo.TestVO3;
import cn.francis.common.enums.CommonErrorCode;
import cn.francis.common.exception.BusinessException;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.francis.chatplatform.modules.session.po.ChatSession;
import cn.francis.chatplatform.modules.session.service.ChatSessionService;
import cn.francis.chatplatform.modules.session.mapper.ChatSessionMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.time.LocalDateTime;

/**
 * @author 张俊辉
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class ChatSessionServiceImpl implements ChatSessionService{
    private final ChatSessionMapper chatSessionMapper;
    @Override
    public Long save(CreateSessionBO session) {
        LambdaQueryWrapper<ChatSession> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(session.getTitle()), ChatSession::getTitle, session.getTitle());
        if (chatSessionMapper.selectCount(wrapper) > 0) {
            throw new BusinessException(CommonErrorCode.TITLE_EXIST.getCode(), CommonErrorCode.TITLE_EXIST.getMessage());
        }
        ChatSession chatSession = new ChatSession();
        chatSession.setUserId(1L);
        chatSession.setTitle(session.getTitle());
        chatSession.setCreateBy("junhui").setCreateTime(LocalDateTime.now()).setUpdateBy("junhui").setUpdateTime(LocalDateTime.now()).build();
        chatSessionMapper.insert(chatSession);
        return chatSession.getId();
    }

    @Override
    public void test(String test) {
        ChatSession chatSession = chatSessionMapper.selectTest(test);
        System.out.println(chatSession);
    }

    @Override
    public void test3(TestVO testVO) {
        ChatSession chatSession = chatSessionMapper.selectTest3(testVO);
        System.out.println(chatSession);
    }

    @Override
    public void test4(TestVO3 testVO) {
        ChatSession chatSession = chatSessionMapper.selectTest4(testVO);
        System.out.println(chatSession);

    }
}




